package cn.iocoder.yudao.module.wine.dal.mysql.supplyoptional;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.wine.dal.dataobject.countnameconfig.CountNameConfigDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyinfo.SupplyInfoDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyoptional.SupplyOptionalDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplytype.SupplyTypeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.app.supplyoptional.vo.*;

/**
 * 供求自选条件 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SupplyOptionalMapper extends BaseMapperX<SupplyOptionalDO> {

    default PageResult<SupplyOptionalDO> selectPage(AppSupplyOptionalPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SupplyOptionalDO>()
                .betweenIfPresent(SupplyOptionalDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SupplyOptionalDO::getId));
    }

    default List<AppSupplyOptionalRespVO> selectSupplyOptionalList(AppSupplyOptionalPageReqVO pageReqVO){
        return selectJoinList(AppSupplyOptionalRespVO.class,new MPJLambdaWrapperX<SupplyOptionalDO>()
                .eqIfPresent(SupplyOptionalDO::getUserId, SecurityFrameworkUtils.getLoginUserId())
                .betweenIfPresent(SupplyOptionalDO::getCreateTime, pageReqVO.getCreateTime())
                .leftJoin(CountNameConfigDO.class,CountNameConfigDO::getId,SupplyOptionalDO::getMarketId)
                .leftJoin(SupplyTypeDO.class,SupplyTypeDO::getId,CountNameConfigDO::getSupplyTypeId)

                .eqIfExists(CountNameConfigDO::getFragranceType, pageReqVO.getFragranceType())
                .eqIfExists(CountNameConfigDO::getSupplyTypeId, pageReqVO.getSupplyTypeId())
                .eqIfExists(CountNameConfigDO::getShowYear, pageReqVO.getShowYear())
                .eqIfExists(CountNameConfigDO::getPacking, pageReqVO.getPacking())

                .selectAll(SupplyOptionalDO.class)
                .selectAs(SupplyTypeDO::getTypeName,AppSupplyOptionalRespVO::getSupplyTypeName)
                .selectAs(CountNameConfigDO::getFragranceType,AppSupplyOptionalRespVO::getFragranceType)
                .selectAs(CountNameConfigDO::getSupplyTypeId,AppSupplyOptionalRespVO::getSupplyTypeId)
                .selectAs(CountNameConfigDO::getCountName,AppSupplyOptionalRespVO::getCountName)
                .selectAs(CountNameConfigDO::getPacking,AppSupplyOptionalRespVO::getPacking)
                .selectAs(CountNameConfigDO::getShowYear,AppSupplyOptionalRespVO::getShowYear)
                .orderByDesc(SupplyOptionalDO::getIsTop)
                .orderByDesc(SupplyOptionalDO::getUpdateTime)


        );
    }
}
